#include "EnemyRedForest.h"

#define BULLET_VECTOR_0 5
#define PI 3.14159265

int CEnemyRedForest::_GunXPosition[3] = { 0, -32, 32 };
int CEnemyRedForest::_GunYPosition[3] = { 0, 8, 8 };
int CEnemyRedForest::_ShootAngle[3] = { 0, 180, 0 };

CEnemyRedForest::CEnemyRedForest()
{

	_count_Time_Enemy_Up = 1;
	_isForestUp = false;
	_count_Time_Enemy_Change = 1;
	_current_Sprite_Forest = 0;
	_frame_Start_Red = GetTickCount();
	now = GetTickCount();
	_tick_Per_Frame = 1000 / FRAME_RATE;


	//// gun
	//_isbullet = false;
	//_gun = false;
	//_tick_per_gun = 700;
	//_tick_bullet = 300;
	//_bullet_start = GetTickCount();
	//_levelBullet = 2;
}

void CEnemyRedForest::LoadResource()
{
	_x = -100;
	_y = -100;
	_EnemyRedForest = CSpriteManager::getInstance()->GetEnemySprite(EnemyRedForest);
	_ListBullet = new CListBullet(6);
	_ShootCount = 0;
}



void CEnemyRedForest::Update(D3DXVECTOR2 ContraPositon)
{

	DWORD now1 = GetTickCount();

	if (now1 - _frame_Start_Red >= _tick_Per_Frame)
	{
		_frame_Start_Red = now1;
		////enemy forest
		if (ContraPositon.x > MARK3 && ContraPositon.x < MARK4 + SCREEN_WIDTH)
		{
			_count_Time_Enemy_Up++;
		}

		if (_count_Time_Enemy_Up > 20)
		{
			_count_Time_Enemy_Change++;
			_count_Time_Enemy_Up = 1;

			if (_count_Time_Enemy_Change % 2 == 0) _isForestUp = true;
			else _isForestUp = false;
		}

		if (_count_Time_Enemy_Up % 20 == 0 && _isForestUp == false)
		{
			_y = _y + 30;

			_IsShootable = true;

			if (ContraPositon.x < _x)
			{
				_current_Sprite_Forest = Next(_current_Sprite_Forest, 1, 1);
			}
			else
			{
				_current_Sprite_Forest = Next(_current_Sprite_Forest, 2, 2);
			}
		}

		if (_count_Time_Enemy_Up % 20 == 0 && _isForestUp == true)
		{
			_y = _y - 30;
			_current_Sprite_Forest = Next(_current_Sprite_Forest, 0, 0);
			_IsShootable = false;

		}
	}

}
void CEnemyRedForest::Render(D3DXVECTOR2 ContraPositon)
{

	if ((ContraPositon.x < SCREEN_WIDTH / 2 && abs(ContraPositon.x - _x) <= SCREEN_WIDTH + FRAMEWIDTH) || abs(ContraPositon.x - _x) < SCREEN_WIDTH / 2 || (ContraPositon.x > GAMEWORLDWIDTH - SCREEN_WIDTH / 2 && abs(_x - ContraPositon.x) < SCREEN_WIDTH + FRAMEWIDTH))
	{

		//now = GetTickCount();

		Update(ContraPositon);

		//Enemy Red Forest
		_EnemyRedForest->Render(_x, _y, _current_Sprite_Forest);
		if (_IsShootable)
		{
			if (GetTickCount() - now >= 800)
			{
				_ListBullet->Shoot(_x + _GunXPosition[_current_Sprite_Forest], _y + _GunYPosition[_current_Sprite_Forest], 3000, BULLET_VECTOR_0 * cos(_ShootAngle[_current_Sprite_Forest] / 180 * PI), BULLET_VECTOR_0 * sin(_ShootAngle[_current_Sprite_Forest] / 180 * PI), 2);
				now = GetTickCount();
			}
		}
		_ListBullet->Render();
	}
}
Box CEnemyRedForest::GetBox()
{
	return Box();
}
CEnemyRedForest::~CEnemyRedForest()
{
}
